package com.cosina.game.crystallight.model.crystal;

import com.cosina.game.crystallight.MediaPlayerAdapter;



public class Box extends CrystalContainer {
	public final int id;
	private final Desk desk;
	public CrystalSeed seed;
	
	public Box(Desk belongDesk,int id) {
		this.desk = belongDesk;
		this.id = id;
	}

	public void detect() {
		if (null == Palm.getContainer()) {
			if (isEmpty() && seed == null) {
				desk.fillSeeds();
			} else if (isEmpty() && seed != null) {
				Crystal newCrystal = seed.mature();
				this.crystal = newCrystal;
				desk.unfeed();
			} else if(isEmpty() == false  && seed == null){
				Palm.setContainer(this);
			}
		} else {
			if(Palm.getContainer()== this){
				Palm.setContainer(null);
				return ;
			}
			if (isEmpty()) {
				MediaPlayerAdapter.dropCrystal();
				CrystalContainer container = Palm.getContainer();
				this.crystal = container.crystal;
				container.crystal = null;
				Palm.setContainer(null);
			}else{
				Palm.setContainer(this);
			}
		}
	}
}
